const db = require('../../lib/conn_oracle')

exports.getSignLinesInfo = async (req, res) => {
    let resDatas
    let status
    let msg
    let sql = `select location,description
               from c##wxw.location
               where areatype = '线路'
                 and location in ('L03','L3B')
               `
    try {
        let signLines = await db.search2(sql)
        status = signLines.errorNum ? 0 : 1
        msg = signLines.errorNum ? "查询失败" : "查询成功"
        resDatas = { signLines }
        res.json({
            status,
            msg,
            resDatas
        })
    } catch (err) {
        res.json({
            status: 0,
            msg: "查询失败",
            resDatas: { err }
        })
    }

}

exports.getCompDateDistribution = async (req, res) => {
    // console.log(req.body)
    let {params} = req.body
    let {jcYear,line} = params
    let resDatas
    let status
    let msg
    let yearWhere = `${jcYear}-12-31`
    let sql = `select x.location
                    ,l.description
                    ,to_char(x.finishdate,'yyyy-mm-dd') as finishdate
                    ,count(x.wonum) as cw
               from c##wxw.xfjiance x
               inner join c##wxw.location l
               on x.location = l.location
               where x.cust_linenum = :line 
                 and x.schedfinish = to_timestamp(:yearWhere,'yyyy-mm-dd hh24:mi:ss.ff')
               group by x.location
                    ,l.description
                    ,to_char(x.finishdate,'yyyy-mm-dd')
               order by x.location
            `
    try {
        let compDateDistribution = await db.search(sql,{line,yearWhere})
        status = compDateDistribution.errorNum ? 0 : 1
        msg = compDateDistribution.errorNum ? "查询失败" : "查询成功"
        resDatas = { compDateDistribution }
        res.json({
            status,
            msg,
            resDatas
        })
    } catch (err) {
        res.json({
            status: 0,
            msg: "查询失败",
            resDatas: { err }
        })
    }
}
